package com.selenium.MavenSelenium;

import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.selenium.base.base;

public class demovirtuemart {
	base ba= base.getInstance();
	static int count = -1;
	int noofmobiles=0;
	public String mobileName;
	
	
	@Test(dataProvider="getData")
	public void virtuemartTest(String browser) throws Throwable
	{
		ba.implicitWait();
		ba.openBrowser(browser);
		ba.gotoURL("defaulturl");
		ba.eventMenu("virtueHeaderMenu","categoryLayout");
		ba.verifyTitle("Welcome to MoWebSo");
		ba.button("mobileViewAll");
		ba.verifyTitle("Mobile Phones");
		
		if(ba.getText("desiredHD").equals("Desire HD"))
		{
			mobileName=ba.getText("desiredHD");
			count++;
			ba.button("desiredHDPdtDetails");
			ba.implicitWait();
			ba.verifyTitle("Mobile Phones :  Desire HD");
			ba.text("addCartText", "2");
			ba.button( "addToCart");
			ba.session.put("mobile_"+count, "mobileName");
			noofmobiles= ba.session.size();
			for(int i=0;i<noofmobiles;i++)
			{
				ba.session.get("mobile_"+i);
			}
			ba.implicitWait();
			
			ba.eventListener("showCart");
			ba.implicitWait();
			ba.verifyTitle("Shopping cart");
			ba.button("continueShop");
			 
		}
		ba.verifyTitle("Mobile Phones");
		ba.implicitWait();
		mobileName=ba.getText("googleNexus");
		ba.implicitWait();
		if(ba.getText("googleNexus").equals("Google Nexus S"))
		{
			count++;
			ba.button("googleNexusPdtDetails");
			ba.implicitWait();
			ba.verifyTitle("Mobile Phones :  Google Nexus S");
			ba.text("addCartText", "4");
			ba.button( "addToCart");
			ba.session.put("mobile_"+count, "mobileName");
			ba.implicitWait();
			noofmobiles= ba.session.size();
			for(int i=0;i<noofmobiles;i++)
			{
				ba.session.get("mobile_"+i);
			}
			ba.eventListener("showCart");
			ba.implicitWait();
			ba.verifyTitle("Shopping cart");
			ba.getText("total");
		}
		ba.verifyTitle("Shopping cart");
		ba.getText("total");
		ba.implicitWait();
		//ba.closeBrowser();
		ba.quitBrowser();
	}
	@DataProvider(parallel=true)
	public Object[][] getData()
	{
		Object[][] data = new Object[2][1];
		data[0][0] = "firefox";
		data[1][0] = "chrome";
		return data;
		
	}
}
